import { getQueryParam } from '@/utils/common'

export const platforms = [
  {
    label: '全部',
    id: -1,
    children: []
  },
  {
    label: '淘宝&天猫',
    id: 1,
    children: [
      {
        label: '淘宝联盟库',
        id: 1,
        key: ['isCoupon', 'categoryId', 'isFree', 'keyword']
      },
      {
        label: '淘宝精品库',
        id: 12,
        key: ['materialId']
      }
    ]
  },
  {
    label: '京东',
    id: 2,
    children: [
      {
        label: '京东库',
        id: 3,
        key: ['keyword', 'isCoupon', 'priceStart', 'priceEnd', 'commissionStart', 'commissionEnd', 'categoryId']
      },
      {
        label: '京东京粉',
        id: 2,
        key: ['eliteId']
      },
      {
        label: '京东精选频道',
        id: 7,
        key: ['eliteId']
      }
    ]
  },
  {
    label: '拼多多',
    id: 3,
    children: [
      {
        label: '拼多多库',
        id: 4,
        key: ['isCoupon', 'categoryId', 'keyword']
      },
      {
        label: '拼多多榜单',
        id: 5,
        key: ['channelType']
      },
      {
        label: '拼多多活动',
        id: 6,
        key: ['activityTags']
      }
    ]
  },
  {
    label: '苏宁',
    id: 4,
    children: [
      {
        label: '苏宁搜索',
        id: 41,
        key: ['keyword']
      }
    ]
  },
  {
    label: '唯品会',
    id: 5,
    children: [
      {
        label: '唯品会搜索',
        id: 51,
        key: ['keyword', 'priceStart', 'priceEnd']
      },
      {
        label: '唯品会频道',
        id: 52,
        key: ['sourceType', 'categoryId']
      },
      {
        label: '唯品会组货',
        id: 8,
        key: ['sourceType', 'categoryId']
      }
    ]
  },
  {
    label: '考拉',
    id: 6,
    children: [
      {
        label: '考拉搜索',
        id: 61,
        key: ['keyword']
      }
    ]
  },
  {
    label: '抖音',
    id: 7,
    children: [
      {
        label: '抖音精选联盟库',
        id: 9,
        key: ['categoryId', 'priceStart', 'priceEnd', 'commissionStart', 'commissionEnd', 'activityId', 'keyword']
      },
      {
        label: '抖音榜单',
        id: 10,
        key: ['sort', 'categoryId']
      }
    ]
  },
  {
    label: '快手',
    id: 8,
    children: [
      {
        label: '快手搜索',
        id: 81,
        key: ['keyword']
      }
    ]
  }
]

export const platformTypesContrast = [
  { id: 1, pId: 1 },
  { id: 12, pId: 1 },
  { id: 3, pId: 2 },
  { id: 2, pId: 2 },
  { id: 7, pId: 2 },
  { id: 4, pId: 3 },
  { id: 5, pId: 3 },
  { id: 6, pId: 3 },
  { id: 41, pId: 4 },
  { id: 51, pId: 5 },
  { id: 52, pId: 5 },
  { id: 8, pId: 5 },
  { id: 61, pId: 6 },
  { id: 9, pId: 7 },
  { id: 10, pId: 7 },
  { id: 81, pId: 8 }
]
export const platformList = [
  { label: '淘宝', value: 1 },
  { label: '京东', value: 2 },
  { label: '拼多多', value: 3 },
  { label: '苏宁', value: 4 },
  { label: '唯品会', value: 5 },
  { label: '考拉', value: 6 },
  { label: '抖音', value: 7 },
  { label: '快手', value: 8 },
  { label: '猫享', value: 9 },
  { label: '阿里巴巴', value: 10 },
  { label: '腾讯云选', value: 11 },
  { label: '美团分销', value: 12 },
  { label: '美团联盟', value: 13 },
  { label: '美团美天赚', value: 14 },
  { label: '阿里本地联盟', value: 15 },
  { label: '团油', value: 16 },
  { label: '滴滴', value: 17 },
  { label: '卡券', value: 18 },
  { label: '千猪-肯德基', value: 19 },
  { label: '千猪-电影票', value: 20 },
  { label: '信用卡', value: 21 },
  { label: '多麦', value: 22 }
]

export const formO = {
  goodsLibraryId: undefined,
  name: undefined,
  type: undefined,
  platformId: -1,
  sectionTitleImg: undefined,
  sectionTitleColour: undefined,
  sectionSubtitleIcon: undefined,
  sectionSubtitleColour: undefined,
  sectionSubtitleBackColor: {
    mainColor: undefined,
    subColor: undefined
  },
  sectionSubtitleText: undefined,
  viewMoreTextColor: undefined,
  viewMoreText: undefined,
  headImageSet: undefined,
  goodsShortTitleSet: undefined,
  filterDisplay: undefined,
  filterDefSet: undefined,
  isOpenShare: undefined,
  shareTitle: undefined,
  shareDesc: undefined,
  shareSmallIcon: undefined,
  appletShareImg: undefined,
  shareButtonImg: undefined,
  sharePosterImg: undefined,
  isSharePosterUserHeadImg: undefined,
  isSharePosterUserNickname: undefined,
  listDisplayStyle: undefined
}

export const allKey = {
  platformType: undefined,
  isCoupon: undefined,
  categoryId: undefined,
  isFree: undefined,
  keyword: undefined,
  eliteId: undefined,
  priceStart: undefined,
  priceEnd: undefined,
  commissionStart: undefined,
  commissionEnd: undefined,
  channelType: undefined,
  activityTags: undefined,
  sourceType: undefined,
  activityId: undefined,
  sort: undefined,
  importFormat: undefined
}

export const linkFormat = (str, target = '') => {
  let url = str.replace(/msmm:\/\/appView\?/g, '').replace(/msmm:\/\/appPage\?/g, '')
  const urlArr = url.split('?')
  const res = urlArr[urlArr.length - 1]
  if (target) {
    return getQueryParam(target, res)
  }
  return res
}

export const linkFormatPath = (str, type = 1) => {
  if (!str) return ''
  if (type != 1) return decodeURIComponent(str)
  const [baseUrl, queryString] = str.split('?path=')
  if (!queryString) return str
  const index = queryString.indexOf('&')
  if (index === -1) return str
  const substringBeforeAmpersand = queryString.substring(0, index)
  const encodedSubstring = encodeURIComponent(substringBeforeAmpersand)
  const newUrl = encodedSubstring + queryString.substring(index)
  return `${baseUrl}?path=${newUrl}`
}
